package com.ybkj.daijia.server.service.impl;

import com.ybkj.daijia.common.Pager;
import com.ybkj.daijia.page.Page;
import com.ybkj.daijia.page.Pageable;
import com.ybkj.daijia.page.impl.PageImpl;
import com.ybkj.daijia.page.impl.PageRequest;
import com.ybkj.daijia.server.mapper.TrainMapper;
import com.ybkj.daijia.server.model.Train;
import com.ybkj.daijia.server.service.SuperviceService;
import com.ybkj.daijia.server.service.TrainService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Shine.
 */
@Service
public class DefaultTrainService implements TrainService {

    @Autowired
    SuperviceService superviceService;
    @Autowired
    private TrainMapper trainMapper;

    @Override
    public Train insert(Train train) {

        trainMapper.insertRecord(train);
        //将驾驶员培训信息上传监管平台
        superviceService.SjpxMessage(train);
        return train;
    }

    @Override
    public int update(Train train) {
        return trainMapper.updateByPrimaryKey(train);
    }

    @Override
    public Train findOne(Long id) {

        return trainMapper.findOne(id);
    }

    @Override
    public void delete(Long id) {
        trainMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Page<Train> queryByEmploy(Long driverId) {

        Pageable pageable = new PageRequest(Pager.getPage(), Pager.getLimit());

        List<Train> content = trainMapper
            .queryByEmploy(driverId, Pager.getOffset(), Pager.getLimit());

        Long total = trainMapper.countByEmploy(driverId);

        return new PageImpl<Train>(content, pageable, total);
    }


}
